package com.java8.ch06;

class Stack {

	int[] stacks = new int[10];
	int pos;

	// Initialize top-of-stack
	public Stack() {
		pos = -1;
	}

	public void push(int item) {
		if (pos == 9) {
			System.out.println("Stack is full.");
		} else {
			stacks[++pos] = item;
		}
	}

	public int pop() {
		if (pos < 0) {
			System.out.println("Stack underflow.");
			return 0;
		} else {
			return stacks[pos--];
		}
	}

}

class TestStack {
	public static void main(String[] args) {
		Stack myStack1 = new Stack();
		Stack myStack2 = new Stack();

		// push some numbers onto the stack
		for (int i = 0; i < 10; i++) {
			myStack1.push(i);
		}
		for (int i = 10; i < 22; i++) {
			myStack2.push(i);
		}
		// pop those numbers off the stack
		System.out.println("Stack in mystack1:");
		for (int i = 0; i < 10; i++) {
			System.out.println(myStack1.pop());
		}
		System.out.println("Stack in mystack2:");
		for (int i = 0; i < 11; i++) {
			System.out.println(myStack2.pop());
		}
	}
}
